package cn.bonoon.controllers.announcement;

import java.util.Date;
import java.util.List;

import cn.bonoon.core.IModuleSelected;
import cn.bonoon.core.plugins.AnnouncementService;
import cn.bonoon.entities.interacting.AnnouncementEntity;
import cn.bonoon.kernel.annotations.Ignore;
import cn.bonoon.kernel.annotations.Transform;
import cn.bonoon.kernel.events.DialogEvent;
import cn.bonoon.kernel.support.models.Item;
import cn.bonoon.kernel.support.models.ObjectEditor;
import cn.bonoon.kernel.support.services.IService;
import cn.bonoon.kernel.util.BoolType;
import cn.bonoon.kernel.web.EmbedType;
import cn.bonoon.kernel.web.annotations.components.AsCheckbox;
import cn.bonoon.kernel.web.annotations.components.AsDateBox;
import cn.bonoon.kernel.web.annotations.components.AsEditor;
import cn.bonoon.kernel.web.annotations.components.AsSelector;
import cn.bonoon.kernel.web.annotations.form.FormEditor;
import cn.bonoon.kernel.web.annotations.form.InsertCell;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyInsert;
import cn.bonoon.kernel.web.handlers.DialogFormInitializer;
import cn.bonoon.kernel.web.models.DialogModel;

@Transform
@FormEditor(value = 2, width = 250)
//@TabHome(name = "公告内容")
//@AsTabs(@TabItem(name = "发布到子系统", value = "/sys/announcement/release.vm", type = TabItemType.PARSE))
@InsertCell(name = "发布到", value = "/sys/release-module.vm", colspan = 1, type = EmbedType.PARSE)
public class AnnouncementEditor extends ObjectEditor 
	implements AnnouncementDefine, DialogFormInitializer<AnnouncementEntity>, IModuleSelected {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1242616601977241807L;

//	@PropertyEditor(value = 0, required = true)
//	@AsComboBox(value = "/s/common/modules/items.do")
//	private String key;

	@PropertyEditor(0)
	@AsCheckbox("是")
	private boolean platform;
	@PropertyEditor(1)
	@AsSelector
	private int type;

	@PropertyEditor(10)
	@AsCheckbox("是")
	private boolean topest;
	@PropertyEditor(11)
	@AsDateBox
	private Date topTo;
	
	@PropertyEditor(value = 20, colspan = 1,required = true)
	@AsEditor
	private String content;
	
	@Ignore
	private String[] keys;
	
	@Override
	public Object init(IService<AnnouncementEntity> service, DialogModel model,
			DialogEvent event, Long id, Object form) throws Exception {
		AnnouncementService announcementService = (AnnouncementService)service;
		List<Item> modules = announcementService.releasePlaform(event, id);
		model.addObject("modules", modules);
		return form;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

//	public String getKey() {
//		return key;
//	}
//
//	public void setKey(String key) {
//		this.key = key;
//	}

	public boolean isPlatform() {
		return platform;
	}

	public void setPlatform(boolean platform) {
		this.platform = platform;
	}

	public String[] getKeys() {
		return keys;
	}

	public void setKeys(String[] keys) {
		this.keys = keys;
	}

	public boolean isTopest() {
		return topest;
	}

	public void setTopest(boolean topest) {
		this.topest = topest;
	}

	public Date getTopTo() {
		return topTo;
	}

	public void setTopTo(Date topTo) {
		this.topTo = topTo;
	}

}
